class Solution:
    def permuteUnique(self, nums: List[int]) -> List[List[int]]:
        ret = []

        def search(left,history):
            nonlocal ret
            if not left:
                ret.append(history)

            for i in set(left):
                left.remove(i)
                left.append(i)
                search(left[:-1],history+[i])

        search(nums,[])
        return ret